package com.xinz.srmi.impl.serialization;

import java.util.ArrayList;
import java.util.List;

public class BaseObjectSerialer {
	static class StringSerialer extends Serialer{
		@Override
		public void read(Accessor accessor, BeanInputStream in)
				throws Exception {
			accessor.set(in.readUTF());
		}
		@Override
		public void write(Accessor accessor, BeanOutputStream out)
				throws Exception {
			out.writeUTF((String)accessor.get());
		}
		@Override
		public Class getType() {
			return String.class;
		}
	}
	static class ArrayListSerialer extends Serialer{
		@Override
		public void read(Accessor accessor, BeanInputStream in)
				throws Exception {
			int size = in.readShort();
			ArrayList<Object> list = new ArrayList<Object>();
			in.addBuff(list);
			Accessor temp = new ObjectAccessor();
			for(int i=0;i<size;i++){
				in.readAccssor(temp);
				list.add(temp.get());
			}
			accessor.set(list);
		}
		@Override
		public void write(Accessor accessor, BeanOutputStream out)
				throws Exception {
			ArrayList<Object> list= (ArrayList<Object>) accessor.get();
			out.addBuff(list);
			int size = list.size();
			out.writeShort(size);
			Accessor temp = new ObjectAccessor();
			for(int i=0;i<size;i++){
				temp.set(list.get(i));
				out.writeAccessor(temp);
			}
		}
		@Override
		public Class getType() {
			return ArrayList.class;
		}
	}
	
	
}



